package com.douqu.game.core.entity.goods;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.GameObject;

/**
 * Created by bean on 2017/7/22.
 */
public class Goods extends GameObject {

    /**
     * 道具类型
     * 1为消耗品、2为任务道具、3为合成材料、4为卡片碎片
     */
    public int type;

    /***
     * 当前已存放数量
     */
    public int count;

    @Override
    public void copyTo(GameObject gameObject)
    {
        super.copyTo(gameObject);

        Goods goods = (Goods) gameObject;
        goods.type = this.type;
        goods.count = this.count;
    }

    @Override
    public void writeTo(ByteBuffer buffer)
    {
        super.writeTo(buffer);

        buffer.writeShort(count);
    }

    @Override
    public void loadFrom(ByteBuffer buffer)
    {
        super.loadFrom(buffer);

        count = buffer.readShort();
    }


    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count < 0 ? 0 : count;
    }


    @Override
    public String toString() {
        return "Goods{" +
                "type=" + type +
                ", count=" + count +
                "} " + super.toString();
    }
}
